package com.fili.core.svn.components;

import com.fili.core.svn.SvnEntry;

import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * Created by Claudiu-Florin FILIMON
 * Date: Oct 20, 2006
 * Time: 12:04:06 PM
 * Revision: 0
 */
public class CheckLabel extends JLabel
{
    private CheckNode node;

    public CheckLabel(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus)
    {
        node = (CheckNode) value;
        Object obj = node.getUserObject();
        if (obj == null)
        {
            setText("ROOT");
            setToolTipText(null);
        }
        if (obj instanceof SvnEntry)
        {
            SvnEntry entry = (SvnEntry) obj;
            setText(entry.name);
            String s = "kind: <b>" + entry.kind + "</b><br>revision: <b>" + entry.commitRevision + "</b><br>";
            setToolTipText(s);
        }
        if (expanded)
            setIcon(SvnTree.icoFolderOpened);
        else
            setIcon(SvnTree.icoFolderClosed);
    }


    public void paint(Graphics g)
    {
        super.paint(g);
        Image img = null;

        switch (node.getType())
        {
            case CheckNode.CHECK_BLUE:
                img = SvnTree.icoOverlayBlue;
                break;
            case CheckNode.CHECK_GREEN:
                img = SvnTree.icoOverlayGreen;
                break;
            case CheckNode.CHECK_RED:
                img = SvnTree.icoOverlayRed;
                break;
            case CheckNode.CHECK_WAIT:
                img = SvnTree.icoOverlayWait;
                break;
        }
        if (img != null)
            g.drawImage(SvnTree.icoOverlayWait, 0, 0, null);
    }
}
